<!DOCTYPE html>
<!--[if IE 8]> <html  class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html  class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
    <head>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="${jpath}/assets/public/css/bootstrap.min.css"/>
        <link rel="stylesheet" type="text/css" href="${jpath}/assets/public/font-awesome/css/font-awesome.min.css"/>
        <link rel="stylesheet" type="text/css" href="${jpath}/assets/public/css/public.css"/>
        <!-- ztree-->
        <link href="${jpath}/assets/public/plugins/jquery-ztree/3.5.12/css/zTreeStyle/zTreeStyle.min.css"
              rel="stylesheet"
              type="text/css"/>
    </head>
<body>
<div class="container-fluid" style="height: 400px;overflow: auto;">
    <div class="col-xs-12">
        <div id="ztree" class="ztree"></div>
    </div>
</div>
<div class="row navbar-fixed-bottom">
    <div class="col-xs-12 text-center">
        <input type="button" class="btn btn-info btn-sm" value="确定" onclick="doSave()"/>
        <input type="button" class="btn btn-cancle  btn-sm" value="关闭" onclick=" top.$.bootbox.hideAll();"/>
    </div>
</div>
</body>
<script src="${jpath}/assets/public/js/jquery.min.js"></script>
<script src="${jpath}/assets/public/js/bootstrap.min.js"></script>
<script src="${jpath}/assets/public/js/public.js"></script>
<script src="${jpath}/assets/public/js/jQuery.resizeEnd.min.js"></script>
<script src="${jpath}/assets/public/js/html5shiv.min.js"></script>
<script src="${jpath}/assets/public/js/respond.min.js"></script>
<!-- ztree-->
<script type="text/javascript"
        src="${jpath}/assets/public/plugins/jquery-ztree/3.5.12/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">

    var url = "${base}/organization/view/treeList";

    //ztree
    var setting = {
        callback: {
            onDblClick: function (event, treeId, treeNode) {
                if (treeNode != null) {
                    doInfo(treeNode.id, treeNode.name);
                }
            },
//            beforeClick: function (treeId, treeNode, clickFlag) {
//                if (treeNode.isParent||treeNode.level==0) {
//                    return false;
//                }
//                return true;
//            },
//            beforeDblClick: function (treeId, treeNode, clickFlag) {
//                if (treeNode.isParent||treeNode.level==0) {
//                    return false;
//                }
//                return true;
//            },
            onAsyncSuccess: function (event, treeId, treeNode, msg) {
                if (msg.length <= 0 && treeId) {
                    $("#" + treeId).html("无数据");
                }
            },
            onAsyncError: function (event, treeId, treeNode, msg) {
                if (treeId) {
                    $("#" + treeId).html("系统异常");
                }

            }
        },
        async: {
            dataType: 'jsonp',
            type: "get",
            enable: true,
            url: url
        }
    };

    function doInfo(id, name) {
        var idField = tools.getQueryString('idField');
        var textField = tools.getQueryString('textField');
        var fn = tools.getQueryString('fn');
        if (typeof fn == 'function') {
            eval("top." + fn + "(" + id + "," + name + ")");
        } else {
            var contentFrame = tools.getCurrentFrame();
            if (contentFrame) {
                var contentFrameDoc = contentFrame.document;
                var oldName = $("#" + textField, contentFrameDoc).val();
                $("#" + idField, contentFrameDoc).val(id);
                $("#" + textField, contentFrameDoc).val(name);
                $("#" + textField, contentFrameDoc)[0].focus();
                if ("companyId" == idField) {
                    var $organizationId = $("#organizationId", contentFrameDoc);
                    var $organizationName = $("#organizationName", contentFrameDoc);
                    if ($organizationId.length > 0 && $organizationName.length > 0 && name != oldName) {
                        $organizationId.val("");
                        $organizationName.val("");
                    }
                }
                ;
                setTimeout(function () {
                    $("#" + textField, contentFrameDoc)[0].blur();
                }, 100);

            }
            else {
                var oldName = $("#" + textField, top.window.document).val();
                $("#" + idField, top.window.document).val(id);
                $("#" + textField, top.window.document).val(name);
                $("#" + textField, top.window.document)[0].focus();
                if ("companyId" == idField) {
                    var $organizationId = $("#organizationId", top.window.document);
                    var $organizationName = $("#organizationName", top.window.document);
                    if ($organizationId.length > 0 && $organizationName.length > 0 && name != oldName) {
                        $organizationId.val("");
                        $organizationName.val("");
                    }
                }
                ;
                setTimeout(function () {
                    $("#" + textField, top.window.document)[0].blur();
                }, 100);
            }

            top.$.bootbox.hideAll();
        }
    }


    function doSave() {
        var treeObj = $.fn.zTree.getZTreeObj("ztree");
        var nodes = treeObj.getSelectedNodes();//获得选中节点数据集合
        if (nodes.length > 0) {
            doInfo(nodes[0].id, nodes[0].name);
        }
        else {
            top.$.bootbox.hideAll();
        }
    }

    $(function () {
        $.fn.zTree.init($("#ztree"), setting, null);
    })
</script>
